package com.seal.yoyoshop.adminweb;

import com.seal.yoyoshop.bin.User;
import com.seal.yoyoshop.service.UserService;
import com.seal.yoyoshop.service.impl.UserServiceImpl;
import com.seal.yoyoshop.util.PageUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UserListServlet", value = "/admin/userList")
public class UserListServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("flag",2);
        String pagestr = request.getParameter("page");
        int page = Integer.parseInt(pagestr);
        String sizestr = request.getParameter("size");
        int size = Integer.parseInt(sizestr);

        List<User> userList = userService.getUserList(page,size);
        request.setAttribute("userList",userList);

        long count = userService.getUserCount();
        String pageInfo = PageUtil.getPageTool(request, count, page, size);
        request.setAttribute("pageTool",pageInfo);

        request.getRequestDispatcher("/admin/user_list.jsp").forward(request,response);
    }
}
